import global from '@/views/Global.vue'
import DivLabel from '@/utils/divLabel'
let coverage = {
    methods: {
        /**
         * @brief 添加施工部位倾斜摄影
         * @url {url} 倾斜url
         * @checkbox {str} 绑定的checkbox 
         * @returns 返回所添加url的倾斜摄影图层
         */
        add(url, checkbox, ) {
            const viewer = global.viewer
            if (!checkbox) {
                viewer.scene.primitives.remove(viewer.tiles)
                return
            }
            const tiles = new Cesium.Cesium3DTileset({
                url: url,
            });
            viewer.tiles = tiles
            viewer._cesiumWidget._creditContainer.style.display = "none";
            viewer.scene.primitives.add(tiles);
            return viewer.tiles
        },
        /**
         * @brief 仅添加文字label
         * @param {string} id entity的id
         * @param {number} lon 经度
         * @param {number} lat 纬度
         * @param {number} hei 高程
         * @param {string} text 文字内容
         * @param {string} font 字体大小和family
         * @param {string} tcolor 字体颜色
         * @param {number} left 左偏移
         * @param {number} top 上偏移
         * @param {number} disableDepthTestDistance 范围高度内无视地形
         * @returns 
         */
        addLabel(id,lon,lat,hei,text,font,tcolor,left,top,disableDepthTestDistance) {
            const viewer = global.viewer
            const bc = tcolor ? tcolor : Cesium.Color.WHITE
            const label = viewer.entities.add({
                position: Cesium.Cartesian3.fromDegrees(lon, lat, hei),
                label: { //文字标签
                    id,
                    text: text,
                    font: font, // 15pt monospace
                    scale: 0.5,
                    // style: Cesium.LabelStyle.FILL,
                    fillColor: bc,
                    pixelOffset: new Cesium.Cartesian2(left, top), //偏移量
                    showBackground: true,
                    backgroundColor: Cesium.Color.WHITE,  //背景顔色
                    backgroundPadding : new Cesium.Cartesian2(20,10),
                    disableDepthTestDistance
                },
            })
            return label
        },
        /**
         * @brief 添加labels实体
         * @name {str} name 
         * @parent {str} parent 
         * @id {str} id 
         * @lon {number} 经度 
         * @lat {number} 纬度 
         * @hei {number} 高 
         * @color {str} color 
         * @pixelSize {number} pixelSize 
         * @outlineWidth {number} outlineWidth 
         * @show {boolean} show 
         * @disableDepthTestDistance {number} 最远可见距离
         * @text {str} 广告牌文字
         * @left {number} 左右偏移
         * @top {number} 上下偏移
         */
        billboard(name, id, lon, lat, hei, color, pixelSize, outlineWidth, show, disableDepthTestDistance, text, left, top) {
            const viewer = global.viewer
            name = viewer.entities.add({
                id,
                position: Cesium.Cartesian3.fromDegrees(lon, lat, hei),
                point: {
                    color: Cesium.Color.fromCssColorString(color),
                    pixelSize,
                    outlineColor: Cesium.Color.WHITE,
                    outlineWidth,
                    show,
                    disableDepthTestDistance
                },
                label: { //文字标签
                    text: text,
                    font: '50px Helvetica', // 15pt monospace
                    scale: 0.5,
                    style: Cesium.LabelStyle.FILL,
                    fillColor: Cesium.Color.WHITE,
                    pixelOffset: new Cesium.Cartesian2(left, top), //偏移量
                    showBackground: true,
                    // backgroundColor: new this.Cesium.Color(26 / 255, 196 / 255, 228 / 255, 1.0)   //背景顔色
                },
            })
            return name
        },
        /**
         * @brief 添加折线
         * @id {str} id 
         * @positions {Array} 坐标数组[x1,y1,x2,y2] 
         * @width {number} 线宽  
         * @material {str} 材质颜色 
         * @show {boolean} show 默认true
         * @zIndex {number} zIndex 层级
         * @clampToGround {boolean} 是否贴地 
         */
        polyline(id, positions, width, material, show=true, zIndex, clampToGround) {
            const viewer = global.viewer
            let polyline = viewer.entities.add({
                id,
                polyline: {
                    positions: this.getPointArr(positions),
                    width,
                    material,
                    show,
                    clampToGround,
                    zIndex
                }
            })
            return polyline
        },
        /**
         * 
         * @pos1 {number} pos1 点坐标lon
         * @pos2 {number} pos2 点坐标lat
         * @poiSize {number} poiSize 字体大小
         * @poiCol {string} poiCol 字体颜色
         * @linCol {string} linCol 边框线颜色
         * @lineSize {number} lineSize 边框线宽
         * @returns 
         */
        addPoint(pos1,pos2,poiSize,poiCol,linCol,lineSize,disableDepthTestDistance){
            const viewer = global.viewer
            const pointEntity = viewer.entities.add({
                position: Cesium.Cartesian3.fromDegrees(pos1, pos2),
                point: {
                    // 点的大小（像素）
                    pixelSize: poiSize,
                    // 点位颜色，fromCssColorString 可以直接使用CSS颜色
                    color: Cesium.Color.fromCssColorString(poiCol),
                    // 边框颜色
                    outlineColor: Cesium.Color.fromCssColorString(linCol),
                    // 边框宽度(像素)
                    outlineWidth: lineSize,
                    // 是否显示
                    show: true,
                    disableDepthTestDistance
                  }
            })
            return pointEntity
        },
        /**
         * 
         * @entityId {string} 需要被移除的实体id 
         */
        removeEntity(entityId){
            const viewer = global.viewer
            let entity = viewer.entities.getById(entityId)
            viewer.entities.remove(entity)
        },
        /**
         * @brief 添加labels实体
         * @parent {str} parent 
         * @id {str} id 
         * @lon {number} 经度 
         * @lat {number} 纬度 
         * @hei {number} 高 
         * @color {str} color 
         * @pixelSize {number} pixelSize 
         * @outlineWidth {number} outlineWidth 
         * @show {boolean} show 
         * @disableDepthTestDistance {number} 最远可见距离
         * @text {str} 广告牌文字
         * @left {number} 左右偏移
         * @top {number} 上下偏移
         * @font {string} 字体样式
         */
        historyBillboard(id, lon, lat, hei, color, pixelSize, outlineWidth, show, disableDepthTestDistance, text, left, top,font,tcolor) {
            const viewer = global.viewer
            const bc = tcolor ? tcolor : Cesium.Color.WHITE
            const billboard = viewer.entities.add({
                id,
                position: Cesium.Cartesian3.fromDegrees(lon, lat, hei),
                point: {
                    color: color,
                    pixelSize,
                    outlineColor: Cesium.Color.WHITE,
                    outlineWidth,
                    show,
                    disableDepthTestDistance
                },
                label: { //文字标签
                    text: text,
                    font: font, // 15pt monospace
                    scale: 0.5,
                    // style: Cesium.LabelStyle.FILL,
                    fillColor: bc,
                    pixelOffset: new Cesium.Cartesian2(left, top), //偏移量
                    showBackground: true,
                    backgroundColor: Cesium.Color.WHITE,  //背景顔色
                    backgroundPadding : new Cesium.Cartesian2(20,10),
                    disableDepthTestDistance
                },
            })
            return billboard
        },
        addPolygon(id,positionArr){
            const viewer = global.viewer
            let polygon = viewer.entities.add({
                id,
                polyline: {
                    positions:Cesium.Cartesian3.fromDegreesArray(positionArr),
                    width: 0,
                    material: new Cesium.Color.fromBytes(0,191,255,100),
                    clampToGround: true,
                  },
                polygon: {
                    show: true,
                    hierarchy: Cesium.Cartesian3.fromDegreesArray(positionArr),
                    // extrudedHeight,
                    material: new Cesium.Color.fromBytes(0,191,255,100),
                    // height: 1010,
                    // clampToGround: true,
                    // zIndex:10200,
                    // closeTop: false,
                    // perPositionHeight: true,
                    // disableDepthTestDistance:5200000
                },
                
            })
            return polygon
        },
    },
}
export default coverage